<template>
	<view class="oa-content tn-safe-area-inset-bottom">
		<!-- 顶部自定义导航 -->
		<tn-nav-bar fixed alpha customBack>
			<view slot="back" class='tn-custom-nav-bar__back' @click="goBack">
				<text class='icon tn-icon-left'></text>
				<text class='icon tn-icon-home-capsule-fill'></text>
			</view>
		</tn-nav-bar>

		<view class="top-info" :style="{paddingTop: vuex_custom_bar_height + 'px'}">
			<!-- <view class="tn-text-center" style="position: absolute;top: 20rpx;right:20rpx;font-size: 200rpx;opacity: 0.1;">
        <view class="tn-icon-trophy-fill tn-color-white"></view>
      </view> -->
			<view
				class="tn-margin tn-padding-left-sm tn-padding-bottom-xl tn-padding-top tn-color-white tn-text-center">
				<!-- <view class="">
					<text>{{USER.name}}</text>

				</view> -->
				<view class="tn-text-bold tn-padding-top-xs" style="font-size:70rpx">{{USER.name}}</view>
			</view>
			<!-- <view class="tn-color-white">
				<view class="tn-flex tn-flex-col-center tn-text-center">
					<view class="justify-content-item tn-flex-1">
						<view class="tn-text-sm" style="opacity: 0.6;">持仓盈亏 (元)</view>
						<view class="tn-text-lg tn-text-bold tn-padding-top-xs">+ 608.62</view>
					</view>
					<view class="justify-content-item tn-flex-1">
						<view class="tn-text-sm" style="opacity: 0.6;">持仓份额 (份)</view>
						<view class="tn-text-lg tn-text-bold tn-padding-top-xs">+ 26.09%</view>
					</view>
					<view class="justify-content-item tn-flex-1">
						<view class="tn-text-sm" style="opacity: 0.6;">累计盈亏 (元)</view>
						<view class="tn-text-lg tn-text-bold tn-padding-top-xs">1,506.22</view>
					</view>
				</view>
			</view> -->
		</view>

		<view class="">
			<view class="tn-padding-top">
				<view class="tn-flex tn-flex-row-between tn-flex-col-center">
					<view class="justify-content-item tn-margin tn-text-bold tn-text-lg">
						业务数据
					</view>
					<view
						class="justify-content-item tn-margin-right tn-padding-xs tn-text-sm tn-bg-gray--light tn-radius tn-color-gray--dark">
						<text class="tn-padding-left-xs tn-padding-right-xs">今天</text>
						<text class="tn-icon-down tn-padding-right-xs"></text>
					</view>
				</view>

				<view class="tn-flex tn-flex-wrap tn-padding-bottom" style="margin: 15rpx;">
					<view v-for="(item, index) in sides" :key="index" style="width: 50%;" @click="to(item)">
						<view class="tn-flex tn-flex-row-between tn-flex-col-center tn-bg-gray--light"
							style="margin: 15rpx;padding: 30rpx 20rpx;border-radius: 15rpx;">
							<view class="justify-content-item ">
								<view class="tn-flex tn-flex-col-center tn-flex-row-left">
									<view
										class="icon12__item--icon tn-flex tn-flex-row-center tn-flex-col-center tn-color-white"
										:style="'background-color:'+ (tuniaoData[index] ? tuniaoData[index].color : '#FB6A67') +';'">
										<view
											:class="[`tn-icon-${tuniaoData[index] ? tuniaoData[index].icon : 'cube-fill'}`]">
										</view>
									</view>
									<view class="">
										<view class="tn-padding-right tn-padding-left-sm">
											<text style="font-size: 42rpx;">{{item.count}}</text>
											<text class="tn-text-sm tn-padding-left-xs" style="opacity: 0.7;"></text>
										</view>
										<view
											class="tn-padding-right tn-padding-top-xs tn-text-sm tn-padding-left-sm tn-text-ellipsis tn-color-gray">

											<text class="tn-padding-right-xs">{{ item.name }}</text>

										</view>
									</view>
								</view>
							</view>
						</view>
					</view>
				</view>

			</view>
		</view>

	</view>
</template>

<script>
	import template_page_mixin from '@/libs/mixin/template_page_mixin.js'
	import * as CustomerApi from '@/api/crm/customer'
	import * as ClueApi from '@/api/crm/clue'
	import * as ReceivableApi from '@/api/crm/receivable'
	import * as ContractApi from '@/api/crm/contract'
	import * as ReceivablePlanApi from '@/api/crm/plan'

	export default {
		mixins: [template_page_mixin],
		data() {
			return {
				clueFollowCount: 0,
				customerFollowCount: 0,
				customerPutPoolRemindCount: 0,
				customerTodayContactCount: 0,
				contractAuditCount: 0,
				contractRemindCount: 0,
				receivableAuditCount: 0,
				receivablePlanRemindCount: 0,
				sides: [{
						name: '今日需联系客户',
						menu: 'customerTodayContact',
						count: 0,
						link: '/crm/customer/index?contactStatus=1'
					},
					{
						name: '分配给我的线索',
						menu: 'clueFollow',
						count: 0,
						link: '/crm/clue/index'
					},
					{
						name: '分配给我的客户',
						menu: 'customerFollow',
						count: 0
					},
					{
						name: '待进入公海的客户',
						menu: 'customerPutPoolRemind',
						count: 0
					},
					{
						name: '待审核合同',
						menu: 'contractAudit',
						count: 0
					},
					{
						name: '待审核回款',
						menu: 'receivableAudit',
						count: 0
					},
					{
						name: '待回款提醒',
						menu: 'receivablePlanRemind',
						count: 0
					},
					{
						name: '即将到期的合同',
						menu: 'contractRemind',
						count: 0
					}
				],
				tuniaoData: [{
						title: '1,209',
						icon: 'cube-fill',
						color: '#FB6A67',
						number: '+21%',
						updown: '#00D05E',
					},
					{
						title: '609',
						icon: 'cube-fill',
						color: '#FFAC00',
						number: '+18%',
						updown: '#00D05E',
					},
					{
						title: '9,613',
						icon: 'cube-fill',
						color: '#957BFE',
						number: '-12%',
						updown: '#FB6A67',
					},
					{
						title: '3,822',
						icon: 'cube-fill',
						color: '#4B98FE',
						number: '+16%',
						updown: '#00D05E',
					},
					{
						title: '609',
						icon: 'cube-fill',
						color: '#00C8B0',
						number: '+22%',
						updown: '#00D05E',
					},
					{
						title: '9,613',
						icon: 'cube-fill',
						color: '#00B9FE',
						number: '-16%',
						updown: '#FB6A67',
					},
					{
						title: '3,822',
						icon: 'cube-fill',
						color: '#F674D6',
						number: '+21%',
						updown: '#00D05E',
					},
					{
						title: '3,822',
						icon: 'cube-fill',
						color: '#FE871B',
						number: '+18%',
						updown: '#00D05E',
					}
				],
			};
		},
		onShow() {
			this.getCount()
		},
		onLoad() {},
		onReady() {},
		mounted() {},
		methods: {
			to(item) {
				this.pages.to(item.link, item.param ?? {})
			},
			getCount() {
				// 获取今日需联系客户数量
				CustomerApi.getTodayContactCustomerCount().then(
					(res) => {
						this.customerTodayContactCount = res || 0
						this.sides[0].count = this.customerTodayContactCount
					}
				).catch(err => {
					console.error('获取今日需联系客户数量失败:', err)
				})

				// 获取待进入公海的客户数量
				CustomerApi.getPutPoolRemindCustomerCount().then(
					(res) => {
						this.customerPutPoolRemindCount = res || 0
						this.sides[3].count = this.customerPutPoolRemindCount
					}
				).catch(err => {
					console.error('获取待进入公海的客户数量失败:', err)
				})

				// 获取分配给我的客户数量
				CustomerApi.getFollowCustomerCount().then(
					(res) => {
						this.customerFollowCount = res || 0
						this.sides[2].count = this.customerFollowCount
					}
				).catch(err => {
					console.error('获取分配给我的客户数量失败:', err)
				})

				// 注意：以下API调用需要相应的API模块，暂时注释掉
				// 如果需要使用，请先导入相应的API模块
				/**/
				ClueApi.getFollowClueCount().then((count) => {
					this.clueFollowCount = count
					this.sides[1].count = this.clueFollowCount
				})
				ContractApi.getAuditContractCount().then((count) => {
					this.contractAuditCount = count
					this.sides[4].count = this.contractAuditCount
				})
				ContractApi.getRemindContractCount().then((count) => {
					this.contractRemindCount = count
					this.sides[7].count = this.contractRemindCount
				})
				ReceivableApi.getAuditReceivableCount().then((count) => {
					this.receivableAuditCount = count
					this.sides[5].count = this.receivableAuditCount
				})
				ReceivablePlanApi.getReceivablePlanRemindCount().then(
					(count) => {
						this.receivablePlanRemindCount = count
						this.sides[6].count = this.receivablePlanRemindCount
					}
				)

			}
		},
	};
</script>
<style lang="scss" scoped>
	/* 胶囊*/
	.tn-custom-nav-bar__back {
		width: 100%;
		height: 100%;
		position: relative;
		display: flex;
		justify-content: space-evenly;
		align-items: center;
		box-sizing: border-box;
		background-color: rgba(0, 0, 0, 0.15);
		border-radius: 1000rpx;
		border: 1rpx solid rgba(255, 255, 255, 0.5);
		color: #FFFFFF;
		font-size: 18px;

		.icon {
			display: block;
			flex: 1;
			margin: auto;
			text-align: center;
		}

		&:before {
			content: " ";
			width: 1rpx;
			height: 110%;
			position: absolute;
			top: 22.5%;
			left: 0;
			right: 0;
			margin: auto;
			transform: scale(0.5);
			transform-origin: 0 0;
			pointer-events: none;
			box-sizing: border-box;
			opacity: 0.7;
			background-color: #FFFFFF;
		}
	}

	.oa-content {
		max-width: 640px;
		margin: 0 auto;
		// background-color: #F8F7F8;
		min-height: 100vh;
		padding-bottom: 60rpx;
		padding-bottom: calc(80rpx + env(safe-area-inset-bottom) / 2);
		padding-bottom: calc(80rpx + constant(safe-area-inset-bottom));
	}

	.top-info {
		position: relative;
		background: linear-gradient(90deg, #3668FC, #395ACD);
		top: 0;
		width: 100%;
		height: 580rpx;
		transition: all 0.25s ease-out;
		z-index: -1;
	}

	.top-info:before {
		content: "";
		position: absolute;
		top: 0;
		left: 0;
		bottom: 0;
		right: 0;
		z-index: -1;
		mask-image: linear-gradient(to bottom, transparent, black);
		background: linear-gradient(90deg, #395ACD, #3668FC);

	}

	/* 间隔线 start*/
	.tn-strip-bottom {
		width: 100%;
		border-bottom: 20rpx solid #F8F7F8;
	}

	/* 间隔线小 start*/
	.tn-strip-bottom-min {
		width: 100%;
		border-bottom: 1rpx solid #F8F7F8;
	}

	/* 业务数据 start */
	.icon12 {
		&__item {
			transform: scale(1);
			transition: transform 0.3s linear;
			transform-origin: center center;

			&--icon {
				width: 90rpx;
				height: 90rpx;
				font-size: 50rpx;
				border-radius: 50%;
				position: relative;
				z-index: 1;

				&::after {
					content: " ";
					position: absolute;
					z-index: -1;
					width: 100%;
					height: 100%;
					left: 0;
					bottom: 0;
					border-radius: inherit;
					opacity: 1;
					transform: scale(1, 1);
					background-size: 100% 100%;
					// background-image: url(https://resource.tuniaokj.com/images/cool_bg_image/icon_bg2.png);


				}
			}
		}
	}
</style>